<?php

namespace App\Http\Controllers\Home;

use App\Model\Article;
use App\Model\Topic;
use App\Model\Video;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;

class SearcheController extends Controller
{
    public function index(){

    }
    public function seacherd(Request $request){
                $keyword=$request->keyword;
                $type=$request->type;
                switch ($type){
                    case 'article';
                    $data=Article::search($keyword)->paginate(10);
                    break;
                    case 'topic';
                        $data=Topic::search($keyword)->paginate(10);
                        break;
                    case 'video';
                        $data=Video::search($keyword)->paginate(10);
                        break;
                    default:
                        return back ()->with ('error','没有对应数据');
                        break;
                }
                $data->withPath('/seacherd?keyword='.$keyword.'&type='.$type);
//                dd($data);

                return view('home.search.searcherd',compact('data','type'));
    }
}
